package com.a01_2021.thousandstimes.general.mapper;

import com.a01_2021.thousandstimes.general.entity.SysMenu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author FRQ
 * @since 2021-02-22
 */
@Repository
public interface SysMenuMapper extends BaseMapper<SysMenu> {

    @Insert("<script>" +
            "INSERT INTO sys_menu (id,name,url,des) VALUES " +
            "<foreach item='menu' collection='list' separator=','>" +
            "(#{menu.id},#{menu.name},#{menu.url},#{menu.des})" +
            "</foreach>" +
            "</script>")
    void insertMenu(@Param("list") List<SysMenu> menuList);

    @Select("SELECT id from sys_menu")
    List<Long> getAllMenu();

    @Select("SELECT sys_menu.name from sys_menu " +
            "left join sys_role_menu srm on sys_menu.id = srm.menu_id " +
            "left join sys_role sr on sr.id = srm.role_id " +
            "left join sys_user_role sur on sr.id = sur.role_id " +
            "left join sys_user su on su.id = sur.user_id " +
            "where sur.user_id=#{userId}")
    List<String> getMenuFromUserId(long userId);
}
